




//
//  ZSignDetailViewController.m
//  ZQLearn
//
//  Created by macfeel on 2019/5/10.
//  Copyright © 2019 macfeel. All rights reserved.
//

#import "ZSignDetailViewController.h"
#import "CommonModel.h"
#import "ScoreCell.h"
@interface ZSignDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;

///刷新和加载更多时候用
@property (nonatomic,assign)NSInteger currentPage;


@end

@implementation ZSignDetailViewController
#define cellIdentifier @"score"
////表样板
-(UITableView *)tableView{
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight -52) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 66;
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"ScoreCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
       
        WeakStament(ws);
        _tableView.mj_header = [CustomRefreshHeader headerWithRefreshingBlock:^{
            [ws loadData];
        }];
        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [ws loadMoreData];
        }];

        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}
////总签到列表
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setItemWithTitle:@"签到详情" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    self.dataArray = [NSMutableArray array];
    self.currentPage = 1;
    [self.view addSubview:self.tableView];
    [self loadData];
    // Do any additional setup after loading the view.
}

-(void)loadData{
    
    if (self.currentPage==1) {
        [self.dataArray removeAllObjects];
    }
    NSDictionary *dic = @{@"userInfo.id":[UserInfoSave shareInstance].uid?:@"",@"pageSize":@(30),@"pageIndex":@(self.currentPage)};
    [ZNetworkService getRequestWithBaseUrl:kSignListUrl setParameters:dic success:^(id result) {
        YYLog(@"%@",result);
        if ([result[@"errorCode"]integerValue]==0) {
            NSArray *arr = result[@"result"];
            for (NSDictionary *dic in arr) {
                CommonModel *model = [CommonModel mj_objectWithKeyValues:dic];
                [self.dataArray addObject:model];

            }
            [self.tableView reloadData];
            [self endRefresh];
            if (arr.count==0) {
                [self noMoreData];
            }
        }
    } fail:^(NSError *error) {
        [self endRefresh];
    } delegater:nil];
    
}

#pragma mark - datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CommonModel *model = self.dataArray[indexPath.row];
    ScoreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.timeLab.text = model.createTime;
    cell.jifenLab.text = [NSString stringWithFormat:@"+%@",model.integral];
        return cell;
}

- (void)loadMoreData{
    self.currentPage++;
    [self loadData];
}


- (void)endRefresh{
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}


///没有更多数据
- (void)noMoreData {
    [self.tableView reloadData];
    [self.tableView.mj_footer endRefreshingWithNoMoreData];
}




@end
